<?php
/*
 * @Author: lokei
 * @Date: 2022-12-31 21:21:28
 * @LastEditors: lokei
 * @LastEditTime: 2023-01-02 11:42:43
 * @Description: 
 */

namespace App\Http\Controllers\Widget;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Widget\BannerModel;
use Illuminate\Http\Request;

class BannerController extends Controller
{
    public function list()
    {
        $items = BannerModel::get();
        $res = ResultTool::success();
        $res['data']['banner_list'] = $items;
        return $res;
    }

    public function add(Request $request) {
        $banner = new BannerModel();
        $banner->save();
        $res = ResultTool::success();
        $res['data']['id'] = $banner->id;
        $res['data']['status'] = '0';
        return $res;
    }

    public function update(Request $request) {
        $menu = BannerModel::where('id', '=', $request->input('id'))->first();
        $menu->img = $request->input('img');
		$menu->url = $request->input('url');
        $menu->save();
        $res = ResultTool::success();
        $res['data']['status'] = '0';
        return $res;
    }

    public function delete(Request $request) {
        BannerModel::where('id', '=', $request->input('id'))->delete();
        return ResultTool::success();
    }
}
